package com.AAA.controller.sds;

import com.AAA.entity.*;
import com.AAA.entity.sds.TSdsPlane;
import com.AAA.service.sds.TSdsPlaneService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * (TSdsPlane)表控制层
 *
 * @author makejava
 * @since 2022-10-28 16:14:00
 */
@RestController
@RequestMapping("tSdsPlane")
public class TSdsPlaneController {
    /**
     * 服务对象
     */
    @Autowired
    private TSdsPlaneService service;

    //分页查询
    @GetMapping("queryall")
    public LayData queryall(MyPage myPage, TSdsPlane tSdsPlane){
        PageInfo pageInfo=service.query(myPage,tSdsPlane);
        return new LayData(pageInfo);
    }


    //添加 and 修改
    @RequestMapping("add")
    public LayData add(TSdsPlane tSdsPlane, HttpSession session){
        User user1 = (User) session.getAttribute("user");
        tSdsPlane.setCreatetime(new Date());
        tSdsPlane.setUid(user1.getId());
        if (tSdsPlane.getId()==null){
            tSdsPlane.setCreatetime(new Date());
            return new LayData(service.add(tSdsPlane));
        }else {
            tSdsPlane.setUpdatetime(new Date());
            return new LayData(service.edit(tSdsPlane));
        }
    }
    //开关修改
    @PostMapping("updatas")
    @ResponseBody
    public LayData queryUser(TSdsPlane tSdsPlane){
        boolean status=service.updatas(tSdsPlane);
        return new LayData(status);
    }


    @GetMapping("getByCode")
    public LayData queryByQyCode(TSdsPlane tSdsPlane){
        return new LayData(service.queryByQyCode(tSdsPlane));
    }


}
